473,468 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with tricky "select all" problem

In reference to the following:

http://www.bellecose.com/form.htm

At the top of each column there is a box for "All".

When one is checked I need to check all of (and only) those boxes
underneath.

Now, the rub here is that every checkbox on the page (except the "All"s)
are coded like this:

<input type="checkbox" name="search" value="Rattan">

Well, they don't all have the value "Rattan" obviously. That value changes
from box to box. What does not change is the name "search".

This is because every checkbox represents a keyword search in the form and
must be named "search" in order to have its value included in the search
process. Changing that is not an option.

I know how to do this to check ALL the boxes on the whole page by name.
But that won't work for this. How can I differentiate between just the
boxes below a particular "All"?

Can it be done by putting a particular columns checkboxes in their own
nested table and set its id and work off that? My searching for answers
hasn't yielded much just yet. Any help is appreciated.

Sep 22 '05 #1
3 2430
Oh also I need the All box to toggle on / off the others with check /
uncheck. In the last few minutes I have found some archive help thats
getting me there...

at*****@comcast.net (Adam Toline) wrote in
<96*******************@216.196.97.136>:
In reference to the following:

http://www.bellecose.com/form.htm

At the top of each column there is a box for "All".

When one is checked I need to check all of (and only) those boxes
underneath.

Now, the rub here is that every checkbox on the page (except the "All"s)
are coded like this:

<input type="checkbox" name="search" value="Rattan">

Well, they don't all have the value "Rattan" obviously. That value
changes from box to box. What does not change is the name "search".

This is because every checkbox represents a keyword search in the form
and must be named "search" in order to have its value included in the
search process. Changing that is not an option.

I know how to do this to check ALL the boxes on the whole page by name.
But that won't work for this. How can I differentiate between just the
boxes below a particular "All"?

Can it be done by putting a particular columns checkboxes in their own
nested table and set its id and work off that? My searching for answers
hasn't yielded much just yet. Any help is appreciated.


Sep 22 '05 #2
Adam Toline <at*****@comcast.net> wrote:
I know how to do this to check ALL the boxes on the whole page by name.
But that won't work for this. How can I differentiate between just the
boxes below a particular "All"?


At least one (possibly poor) option is to give them all unique id's of
the form 'type-of-box'+number. You can then check the id of each
element when you loop through the array you obtain from
getElementsByName() and change only those boxes you're concerned with.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Sep 23 '05 #3
Adam Toline wrote:
Oh also I need the All box to toggle on / off the others with check /
uncheck. In the last few minutes I have found some archive help thats
getting me there...

at*****@comcast.net (Adam Toline) wrote in
<96*******************@216.196.97.136>:

In reference to the following:

http://www.bellecose.com/form.htm

At the top of each column there is a box for "All".

When one is checked I need to check all of (and only) those boxes
underneath.

Now, the rub here is that every checkbox on the page (except the "All"s)
are coded like this:

<input type="checkbox" name="search" value="Rattan">

Well, they don't all have the value "Rattan" obviously. That value
changes from box to box. What does not change is the name "search".

This is because every checkbox represents a keyword search in the form
and must be named "search" in order to have its value included in the
search process. Changing that is not an option.

I know how to do this to check ALL the boxes on the whole page by name.
But that won't work for this. How can I differentiate between just the
boxes below a particular "All"?

Can it be done by putting a particular columns checkboxes in their own
nested table and set its id and work off that? My searching for answers
hasn't yielded much just yet. Any help is appreciated.


There are many ways to do this, the basic methods are using divs to
create sets then display them as columns. The other is to use a table.

Your page fits both cases, take your pick - using divs is simpler from a
scripting standpoint but you may find learning the required CSS too
much. Using a table makes it a bit tougher, but not much.

I don't think you should use a checkbox for selecting all, nor should
checking 'none' cause the other sets to be cleared. The script below
clears the other sets only when 'all' is checked.

I've used divs and CSS to do the job, if you want to use a table then
you could work out which column you are in, then create sets of
checkboxes based on the columns. The advantage is that the design
floats, so if you reduce the window width the sets of checkboxes
re-align - try it and see.

You could also create arrays of references to the checkboxes onload,
then just loop through the arrays checking/unchecking as appropriate.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Demo</title>

<style type="text/css">

..titleD {
font-family: verdana, sans-serif;
font-size: 110%;
font-weight: bold;
color: white;
background-color: #336699;
text-align: center;
}
..buttonSet {
font-family: arial, sans-serif;
font-size: 75%;
color: #336699;
background-color: #f8fafc;
float: left;
border-right: 1px solid #336699;
width: 15em;
}

..clickable {
cursor: pointer;
padding-left: 5px;
}

</style>

<script type="text/javascript">

// Array of button set div ids
var divArray = ['set-1','set-2','set-3'];

// Sets the checked status of all the checkboxes in a group to state
// If state is false, other sets are not modified.
// If state is true, other sets are unchecked
function doChecks( el, state )
{
while (el.parentNode && 'div' != el.nodeName.toLowerCase()) {
el = el.parentNode;
}
if ('div' == el.nodeName.toLowerCase()){
var i = divArray.length;
while ( i-- ){
if ( el.id && divArray[i] == el.id ){
checkGroup( el, state );
} else if ( state ) {
checkGroup( document.getElementById(divArray[i]), !state );
}
}
}
}

// Sets all of the checkboxes inside el to state
function checkGroup (el, state)
{
var inputs = el.getElementsByTagName('input');
var i = inputs.length;
while ( i-- ) {
if ( 'checkbox' == inputs[i].type ){
inputs[i].checked = state;
}
}
}

</script>
</head>
<body>

<div id="msg"></div>

<form action="">
<div>
<div id="set-1" class="buttonSet">
<div class="titleD">STYLE</div>
<span class="clickable" onclick="
doChecks(this, true);
"><b>Check all</b></span>&nbsp;/&nbsp;<span class="clickable"
onclick="doChecks(this, false);
"><b>None</b></span><br>
<input type="checkbox" name="Search_search">Alabaster
/ Faux Alabaster<br>
<input type="checkbox" name="Search_search">Architectural
/ Mission<br>
<input type="checkbox" name="Search_search">Art Deco
/ Craftsman / Retro<br>
<input type="checkbox" name="Search_search">Ceramic
/ Paintable / Porcelain<br>
</div>

<div id="set-2" class="buttonSet">
<div class="titleD">FINISH</div>
<span class="clickable" onclick="
doChecks(this, true);
"><b>Check all</b></span>&nbsp;/&nbsp;<span class="clickable"
onclick="doChecks(this, false);
"><b>None</b></span><br>
<input type="checkbox" name="Search_search">Antique
/ Satin Brass<br>
<input type="checkbox" name="Search_search">Beige
/ White / Ivory<br>
<input type="checkbox" name="Search_search">Black
/ Iron<br>
<input type="checkbox" name="Search_search">Bronze
/ Rust<br>
</div>

<div id="set-3" class="buttonSet">
<div class="titleD">BRAND</div>
<span class="clickable" onclick="
doChecks(this, true);
"><b>Check all</b></span>&nbsp;/&nbsp;<span class="clickable"
onclick="doChecks(this, false);
"><b>None</b></span><br>
<input type="checkbox" name="Search_search">Justice Design Group<br>
<input type="checkbox" name="Search_search">Kichler Lighting<br>
<input type="checkbox" name="Search_search">LBL Lighting<br>
<input type="checkbox" name="Search_search">PLC Lighting<br>
</div>

<input type="submit" value="Search for products"
style="float: left; clear: left; margin-top: 15px;">
</div>
</form>

</body></html>

--
Rob
Sep 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
3
by: Jason | last post by:
I'm having some trouble coming up with the correct select statement. Lets say I have the following two tables: ---------------- ---------------- Orders ...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
4
by: bill salkin | last post by:
The code below creates a dataset containing a table called "Customers" from the Northwind database Later on in my code, after the database connection is closed, I need to access this dataset to...
4
by: Lucky | last post by:
hi guys! Currently i'm facing a bit odd situation. i cant modify my code so i have to make changes in SQL Server. the problem is, i've modified one table by adding new column and now i want...
1
by: Jenny | last post by:
Dear all, I have one select which lists one visible element. I want this select can show scrollbar after I click its down arrow, so that i can use the scrollbar to select the element i want. ...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.